home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk1 / getopt / gotest.c < prev   
C/C++ Source or Header  |  1995-03-18  |  967b  |  40 lines

  1. /*  GOtest.c - A test program to exercise getopt().
  2.  
  3.   usage: GOtest -a -b -c -d argument_d -e argument_e -f argument_f argsapoppin
  4.  
  5. */
  6.  
  7. #include <stdio.h>
  8. #include "getopt.h"
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14. int i, option;
  15. char *optstring;
  16. extern char *optarg;
  17. extern int optind, opterr, optopt;
  18.  
  19. /*  optstring is a string of valid options for this program.
  20.     a, b, & c are only flags, and hence have no arguments.
  21.     The colons (:) following d, e, & f indicate that these
  22.     three options require arguments.
  23. */
  24. optstring = "abcd:e:f:";
  25.  
  26. printf("\noptstring: \"%s\", opterr: %d\n", optstring, opterr);
  27.  
  28. /*  Parse the options  (if any)  */
  29. while ((option = getopt(argc, argv, optstring)) != EOF) {
  30.   printf("getopt() returned '%c', optopt: '%c', optarg: \"%s\", optind: %d\n",
  31.     option, optopt, optarg, optind);
  32. }
  33.  
  34. /*  Display the remaining arguments  (if any)  */
  35. for (i = optind; i < argc; i++)
  36.     printf("argv[%d]: \"%s\"\n", i, argv[i]);
  37.  
  38. } /* end main */
  39.  
  40.